var pageSize = 10;
//职称类别
var resourceTypeMap = {};
var rowid=null;
$(document).ready(function(){
	//表格初始化
	initTable();
	genDictSelect('ResourceType','resource_category','1');
	resourceTypeMap=getTransParam('ResourceType');
	//事件绑定
	eventBind();
});

//事件绑定
function eventBind(){
	//带有分页信息的查询
	$("#queryBtn").click(pageQuery).click();
	$("#argeeBtn").on('click',function(){
		showAgreeDialog();
	});
	$("#unargeeBtn").on('click',function(){
		showUnAgreeDialog();
	});
}

//表格初始化
function initTable(){
	$('#studyListTable').bootstrapTable({
		onPageChange: function (number, size) {
			pageSize = size;
			query(number, size);
		},
		onCheck:function (row) {
			rowid=row.id;
		}
	});
}

//带有分页信息的查询
function pageQuery(){
	query(1, pageSize);
};

//分页查询
function query(pageNumber, pageSize){
	var queryCondition={
		pageNumber: pageNumber, 
		pageSize: pageSize,
		params:$("#studyForm").collect()
	}
	
	$.getApiClient('/study/listAgree').post(queryCondition).done(function(data){
	    $('#studyListTable').bootstrapTable('load', data.payload);
	});
};

//在线学习
function showOnlineFormDialog(row){
	if(row.filepath.endWith(".pdf")){
		customRemoteUrlDialog('在线学习','/page/business/study/onView',null);
	}else if(row.filepath.endWith(".mp4")){
		customRemoteUrlDialog('在线学习','/page/business/study/online',null);
	}
}

//查看详情
function showViewFormDialog(row){
	customRemoteUrlDialog('患者详情','/page/business/study/detail?Id='+row.id,null);
}

//审核通过
function showAgreeDialog(){
	if(rowid==null){
		customTimeOutDialog('信息提示','请选择资源后进行审核',null,2000);
	}else{
		$.getApiClient('/study/agree/{id}').setQuery({id:rowid}).put().done(function(data){
			if(data.code == "0"){
				BootstrapDialog.closeAll();
				customTimeOutDialog('信息提示','审核完成',null,2000);
				pageQuery();
			}else{
				customAlertDialog(data.message, '错误提示', null, null);
			}
		});
	}
}

//审核不通过
function showUnAgreeDialog(){
	if(rowid==null){
		customTimeOutDialog('信息提示','请选择资源后进行审核',null,2000);
	}else{
		$.getApiClient('/study/uagree/{id}').setQuery({id:rowid}).put().done(function(data){
			if(data.code == "0"){
				BootstrapDialog.closeAll();
				customTimeOutDialog('信息提示','审核完成',null,2000);
				pageQuery();
			}else{
				customAlertDialog(data.message, '错误提示', null, null);
			}
		});
	}
}

//操作列
function operateFormatter(value, row, index) {	
	var operates=[];
	operates.push('<a class="edit" href="javascript:void(0)" title="查看详细"><i class="fa fa-edit"></i>查看详细</a>');
	operates.push('&nbsp;&nbsp;&nbsp;');
	operates.push('<a class="delete" href="javascript:void(0)" title="查看内容"><i class="fa fa-edit"></i>查看内容</a>');
	return operates.join('');
};


operateEvents = {
	'click .edit' : function(e, value, row, index) {
		showViewFormDialog(row);
	},
	'click .delete' : function(e, value, row, index) {
		showOnlineFormDialog(row);//在线学习
	}

};